{extend name="../../common/view/admin_base"/}

{block name="main"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-table layui-form" id="table" lay-filter="datatable" lay-size="sm"></table>
        </div>
    </div>
</div>

<script type="text/html" id="actionTpl">
    {if isset($btns['admin/group/removeuser']) }
    {assign name="btn" value="$btns['admin/group/removeuser']" /}
    <a class="layui-btn layui-btn-xs removebtn" data-href="{:url($btn['action'])}?gid={$id}&uid={{d.id}}"><i class="{$btn['icon']}"></i>{$btn['name']}</a>
    {/if}
</script>

<script>
    layui.use('table', function(){
        var table = layui.table
            ,form = layui.form;
        table.render({
            elem: '#table'
            ,url:"{:url('admin/group/groupuser')}?id={$id}"
            ,cellMinWidth: 80
            ,cols: [[
                {type:'numbers'}
                ,{field:'username', title:'名称',width:160}
                ,{field:'truename', title:'真实姓名',width:160}
                ,{field:'action', title:'操作',templet: '#actionTpl', unresize: true}
            ]]
            ,page: false
            ,height: 'full-80'
            ,response: {
                statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": 200,
                    "msg": res.msg,
                    "data": res.data
                };
            }
            ,done:function(){
                $.bindactions();
            }
        });

        $.bindactions = function(){
            $(".removebtn").on('click',function(){
                var url = $(this).data('href');
                top.layer.confirm("确定将该用户移出组吗？此操作不能撤销！", {icon: 3, title:'提示'},
                    function(index){
                        top.layer.close(index);
                        $.post(url,function(res){
                            top.layer.msg(res.msg,{
                                offset: '15px'
                                ,icon: 1
                                ,time: 1000
                            },function(){
                                document.location.reload();
                            });
                        });
                    },function (index) {
                    }
                );
            });
        }

    });
</script>
{/block}